#ifndef SONGITEMWIDGET_H
#define SONGITEMWIDGET_H

#include <QWidget>
#include <QLabel>
#include "songitem.h"
#include <QPropertyAnimation>

namespace Ui {
class SongItemWidget;
}

class SongItemWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SongItemWidget(QWidget *parent = nullptr);
    ~SongItemWidget();

    bool eventFilter(QObject *watched, QEvent *event);
    void mouseDoubleClickEvent(QMouseEvent *event);
    void play(bool);
    void setIsLike(bool);
    void setArtist(const QString& artist);
    void setName(const QString& name);
    void setImage(const QString& path);
    void setImage(QPixmap pixmap);
    void setAlbum(const QString& album);
    void setIndex(int index);
    void setDuration(int ms);
    void setUrl(QUrl url);
    void setImageSize(int px);
    void connectManager();
    bool isConnected() {return _connected; }
    void setSongItem(const SongItem& songItem);
    SongItem songItem() const {return _songItem;}
    SongItem& songItem() {return _songItem;}
private:
    void on_songManager_played(QUrl url, bool isPlay);
    void on_songManager_liked(QUrl url, bool isLike);
    void on_songManager_downloaded(QUrl url, const QString& path);
signals:
    void played(int index, bool play);
    void downloaded();

private slots:
    void on_pushButton_index_clicked();
    void on_radioButton_like_toggled(bool checked);

    void on_radioButton_like_clicked(bool checked);

private:
    void setIndexIcon(bool haveIcon, bool hover = false);
    void createAnimation();
    void startAnimation();
    void stopAnimation();
private:
    SongItem _songItem;
    QString _index;
    bool _playing;
    bool _connected;
    bool _mouseInWidget;
    bool _mouseInButton;
    QVector<QPropertyAnimation*> _animations;
    QVector<QLabel*> _animationLabels;
    Ui::SongItemWidget *ui;
};

#endif // SONGITEMWIDGET_H
